package com.borball.store.util;

import java.util.List;

import com.borball.store.dao.MaterialDAO;
import com.borball.store.domain.Material;

public class MaterialUtils {

	private List<Material> materials = null;
	private static MaterialUtils materialUtils = null;
	private MaterialDAO dao;

	private MaterialUtils() {
		dao = new MaterialDAO();
		loadAll();
	}

	private void loadAll() {
		materials = dao.findAll();
	}

	public static MaterialUtils getInstance() {
		if (materialUtils == null)
			materialUtils = new MaterialUtils();
		return materialUtils;
	}

	public List<Material> getAll() {
		return materials;
	}
	
	public void add(Material m){
		dao.add(m);
	}
	
	public Material getByName(String name){
		return dao.findByPK(name);
	}
	

	
	public void update(Material m){
		dao.update(m);
	}
	
	public void delete(Material m){
		dao.delete(m);
	}
	
}
